import type {FormRules} from "element-plus";
import {dateFormatter} from '@/utils/formatTime'
import {DICT_TYPE, getIntDictOptions, getStrDictOptions} from '@/utils/dict'

export const editData = {
  projectNo: "",
  soCode: "",
  soName: "",
  soAddress: "",
  province: "",
  city: "",
  county: "",
  country: "",
  contactsName: "",
  contactsTel: "",
  contactsMobile: "",
  contactsEmail: "",
  firstContacts: "",
  firstContactsTel: "",
  secondContacts: "",
  secondContactsTel: "",
  thirdContacts: "",
  thirdContactsTel: "",
  fourthContacts: "",
  fourthContactsTel: "",
  inspector: "",
  inspectorTel: "",
  soReceiveMemo: "",
  remark: "",
}


// 表单数据
export const initData = reactive({
  projectNo: "",
  authObjectNo: "",
  authObjectName: "",
  authStartTime: "",
  authEndTime: "",
});

// 表单配置项
export const formColumns = reactive([
  {
    xType: "Input",
    label: "项目编号",
    prop: "projectNo",
    clearable: true,
    searchShow: true,
    span: 6
  },
  {
    xType: "Input",
    label: "研究点代码",
    prop: "soCode",
    clearable: true,
    searchShow: true,
    span: 6
  },
  {
    xType: "Input",
    label: "研究点名称",
    prop: "soName",
    clearable: true,
    searchShow: true,
    span: 6
  },
  {
    xType: "Input",
    label: "研究点地址",
    prop: "soAddress",
    clearable: true,
    searchShow: true,
    span: 6,
  },
  {
    xType: "Input",
    label: "省份",
    prop: "province",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "城市",
    prop: "city",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "区县",
    prop: "county",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "国家",
    prop: "country",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "联系人",
    prop: "contactsName",
    clearable: true,
    searchShow: true,
    span: 6,
  },
  {
    xType: "Input",
    label: "电话",
    prop: "contactsTel",
    clearable: true,
    searchShow: true,
    span: 6,
  },
  {
    xType: "Input",
    label: "手机",
    prop: "contactsMobile",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "邮箱",
    prop: "contactsEmail",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "第一联系人",
    prop: "firstContacts",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "第一联系人电话",
    prop: "firstContactsTel",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "第二联系人",
    prop: "secondContacts",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "第二联系人电话",
    prop: "secondContactsTel",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "第三联系人",
    prop: "thirdContacts",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "第三联系人电话",
    prop: "thirdContactsTel",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "第四联系人",
    prop: "fourthContacts",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "第四联系人电话",
    prop: "fourthContactsTel",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "监察员",
    prop: "inspector",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "监察员电话",
    prop: "inspectorTel",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "研究点收货要求",
    prop: "soReceiveMemo",
    clearable: true,
    searchShow: false,
    span: 6,
  },
  {
    xType: "Input",
    label: "备注",
    prop: "remark",
    clearable: true,
    searchShow: false,
    span: 6,
  },
]);

// 表单验证规则
export const formRules = reactive<FormRules>({
  // userName: [
  //   { required: true, message: "请输入名字", trigger: "blur" },
  //   { min: 2, max: 5, message: "名字长度在2-5个字", trigger: "blur" },
  // ],
  // projectNo: [
  //   {
  //     type: "email",
  //     message: "请输入正确的邮箱格式",
  //     trigger: ["blur", "change"],
  //   },
  // ],
  // tmsProjectNo: [
  //   {
  //     required: true,
  //     message: "请选择部门",
  //     trigger: "change",
  //   },
  // ],
});

// 表单搜索项目
export const searchFormData = (() => {
  const filterFormData = () => {
    let data = reactive<any>({});
    const newData = {};
    formColumns.forEach(item => {
      if (item.searchShow) {
        newData[item.prop] = "";
      }
    })
    return data = Object.assign(data, newData)
  }
  return filterFormData()
})()
// 表单搜索项目
export const searchFormColumns = (() => {
  const filterColumns = () => {
    const columns = [] as any;
    formColumns.forEach(item => {
      if (item.searchShow) {
        columns.push(item)
      }
    })
    return reactive<any>(columns)
  }
  return filterColumns()
})()


/***************************table 配置项****************************/
export const tableConfig = reactive({
  showSeletion: false, //是否支持多选
  showHandler: true, // 是否显示操作列
  showIndexColumn: false, // 是否显示索引
  isCheckMemory: true, // 是否需要跨页勾选
  showExpand: false, // 是否是展开行
  showAppend: false, // 插入至表格最后一行之后的内容， 如果需要对表格的内容进行无限滚动操作，可能需要用到这个 slot。 若表格有合计行，该 slot 会位于合计行之上
  indexLabel: "自定义序号", // 自定义索引名称
  handlerConfig: {
    align: "center",
    width: 120
  },
});

export const tableColumns = reactive([
  {
    label: "项目编号",
    prop: "projectNo",
    sortable: false,
    width: 150,
    align: "center",
  },
  {
    xType: "Input",
    label: "研究点代码",
    sortable: false,
    width: 150,
    align: "center"
  },
  {
    label: "研究点名称",
    prop: "soName",
    sortable: false,
    width: 120,
    align: "center"
  },
  {
    label: "研究点地址",
    prop: "soAddress",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "省份",
    prop: "province",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "城市",
    prop: "city",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "区县",
    prop: "county",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "国家",
    prop: "country",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "联系人",
    prop: "contactsName",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "电话",
    prop: "contactsTel",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "手机",
    prop: "contactsMobile",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "邮箱",
    prop: "contactsEmail",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "第一联系人",
    prop: "firstContacts",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "第一联系人电话",
    prop: "firstContactsTel",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "第二联系人",
    prop: "secondContacts",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "第二联系人电话",
    prop: "secondContactsTel",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "第三联系人",
    prop: "thirdContacts",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "第三联系人电话",
    prop: "thirdContactsTel",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "第四联系人",
    prop: "fourthContacts",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "第四联系人电话",
    prop: "fourthContactsTel",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "监察员",
    prop: "inspector",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "监察员电话",
    prop: "inspectorTel",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "研究点收货要求",
    prop: "soReceiveMemo",
    sortable: false,
    width: 120,
    align: "center",
  },
  {
    label: "备注",
    prop: "remark",
    sortable: false,
    width: 120,
    align: "center",
  },
])
